using B.S.Domain.Dto.ShenchanDto;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.ShenchanInfoApplication.Commands
{
    /// <summary>
    /// 创建生产信息命令
    /// </summary>
    public class CreateShenchanInfoCommand : IRequest<APIRequst<string>>
    {
        public ShenchanInfoCreateDTO ShenchanInfo { get; set; } = new();
    }

    /// <summary>
    /// 更新生产信息命令
    /// </summary>
    public class UpdateShenchanInfoCommand : IRequest<APIRequst<int>>
    {
        public ShenchanInfoUpdateDTO ShenchanInfo { get; set; } = new();
    }

    /// <summary>
    /// 删除生产信息命令
    /// </summary>
    public class DeleteShenchanInfoCommand : IRequest<APIRequst<int>>
    {
        /// <summary>
        /// 生产信息ID
        /// </summary>
        public string SID { get; set; } = string.Empty;
    }

    /// <summary>
    /// 批量删除生产信息命令
    /// </summary>
    public class BatchDeleteShenchanInfoCommand : IRequest<APIRequst<int>>
    {
        /// <summary>
        /// 生产信息ID列表
        /// </summary>
        public List<string> SIDs { get; set; } = new();
    }

    /// <summary>
    /// 恢复删除的生产信息命令
    /// </summary>
    public class RestoreShenchanInfoCommand : IRequest<APIRequst<int>>
    {
        /// <summary>
        /// 生产信息ID
        /// </summary>
        public string SID { get; set; } = string.Empty;
    }

    /// <summary>
    /// 批量恢复删除的生产信息命令
    /// </summary>
    public class BatchRestoreShenchanInfoCommand : IRequest<APIRequst<int>>
    {
        /// <summary>
        /// 生产信息ID列表
        /// </summary>
        public List<string> SIDs { get; set; } = new();
    }

    /// <summary>
    /// 查询生产信息列表命令
    /// </summary>
    public class QueryShenchanInfoListCommand : IRequest<APIRequst<APIPageing<List<ShenchanInfoDetailDTO>>>>
    {
        public ShenchanInfoQueryDTO Query { get; set; } = new();
    }

    /// <summary>
    /// 根据ID查询生产信息详情命令
    /// </summary>
    public class GetShenchanInfoByIdCommand : IRequest<APIRequst<ShenchanInfoDetailDTO>>
    {
        /// <summary>
        /// 生产信息ID
        /// </summary>
        public string SID { get; set; } = string.Empty;
    }

    /// <summary>
    /// 根据产品物料ID查询生产信息命令
    /// </summary>
    public class GetShenchanInfoByProductIdCommand : IRequest<APIRequst<List<ShenchanInfoDetailDTO>>>
    {
        /// <summary>
        /// 产品物料ID
        /// </summary>
        public int ProductId { get; set; }
    }

    /// <summary>
    /// 根据工序路线ID查询生产信息命令
    /// </summary>
    public class GetShenchanInfoByProcessrouteIdCommand : IRequest<APIRequst<List<ShenchanInfoDetailDTO>>>
    {
        /// <summary>
        /// 工序路线ID
        /// </summary>
        public int ProcessrouteId { get; set; }
    }

    /// <summary>
    /// 获取生产统计信息命令
    /// </summary>
    public class GetShenchanStatisticsCommand : IRequest<APIRequst<ShenchanStatisticsDTO>>
    {
        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束日期
        /// </summary>
        public DateTime? EndDate { get; set; }

        /// <summary>
        /// 产品物料ID（可选）
        /// </summary>
        public int? ProductId { get; set; }
    }

    /// <summary>
    /// 调试查询命令
    /// </summary>
    public class DebugQueryCommand : IRequest<object>
    {
    }

    /// <summary>
    /// 简化查询命令（只查询生产信息表）
    /// </summary>
    public class SimpleQueryCommand : IRequest<object>
    {
    }

    /// <summary>
    /// 生产统计DTO
    /// </summary>
    public class ShenchanStatisticsDTO
    {
        /// <summary>
        /// 总生产记录数
        /// </summary>
        public int TotalRecords { get; set; }

        /// <summary>
        /// 总生产数量
        /// </summary>
        public int TotalProductCount { get; set; }

        /// <summary>
        /// 涉及的产品种类数
        /// </summary>
        public int ProductVarieties { get; set; }

        /// <summary>
        /// 涉及的工序路线数
        /// </summary>
        public int ProcessrouteCount { get; set; }

        /// <summary>
        /// 按产品统计
        /// </summary>
        public List<ProductStatisticsItem> ProductStatistics { get; set; } = new();

        /// <summary>
        /// 按工序路线统计
        /// </summary>
        public List<ProcessrouteStatisticsItem> ProcessrouteStatistics { get; set; } = new();
    }

    /// <summary>
    /// 产品统计项
    /// </summary>
    public class ProductStatisticsItem
    {
        public int ProductId { get; set; }
        public string ProductName { get; set; } = string.Empty;
        public string ProductCode { get; set; } = string.Empty;
        public int RecordCount { get; set; }
        public int TotalCount { get; set; }
    }

    /// <summary>
    /// 工序路线统计项
    /// </summary>
    public class ProcessrouteStatisticsItem
    {
        public int ProcessrouteId { get; set; }
        public string ProcessrouteName { get; set; } = string.Empty;
        public string ProcessrouteType { get; set; } = string.Empty;
        public int RecordCount { get; set; }
        public int TotalCount { get; set; }
    }

    /// <summary>
    /// 详细调试查询命令 - 逐步分析主查询问题
    /// </summary>
    public class DetailedDebugQueryCommand : IRequest<APIRequst<object>>
    {
    }

    /// <summary>
    /// 获取工序路线下拉框数据命令
    /// </summary>
    public class GetProcessrouteDropdownCommand : IRequest<APIRequst<List<ProcessrouteDropdownDTO>>>
    {
    }

    /// <summary>
    /// 工序路线下拉框DTO
    /// </summary>
    public class ProcessrouteDropdownDTO
    {
        /// <summary>
        /// 工序路线ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 工序路线名称
        /// </summary>
        public string ProcessrouteName { get; set; } = string.Empty;
    }
}
